home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
54809
/
54809.xpi
/
chrome
/
dictCheck-0.0.6.005.jar
/
content
/
libs.js
< prev
Wrap
Text File
|
2010-02-14
|
5KB
|
199 lines
if(!com) var com={};
if(!com.ksla) com.ksla={};
com.ksla.libs = function(){
// FLAGS TO BE SET
const ENABLE_LOGGING = false ;
const PROGRAM_LABEL_PREFIX = "DICTCHECK"; // example 'DICTCHECK'
//-------------------------
var consoleService = null;
var myParser = {
parsedDoc : null,
parser : new DOMParser(),
parse : function(txt){
parsedDoc = parser.parseFromString(txt,"text/xml");
if(parsedDoc.documentElement.tagName == "parsererror"){
var parseErrorText = parsedDoc.documentElement.firstChild.data;
parseErrorText += "\n" + parsedDoc.documentElement.firstChild.nextSibling.firstChild.data;
alert(parseErrorText);
return null;
}
else return parsedDoc;
}
};
function parseCurrentDate(date){
var t = null;
if (date==null){
return null;
}
var h = date.getHours();
if (h <= 9) {
h = '0' + h;
}
var m = date.getMinutes();
if (m <= 9) {
m = '0' + m;
}
var s = date.getSeconds();
if (s <= 9) {
s = '0' + s;
}
var milis = date.getMilliseconds();
if (9 < milis && milis <= 99) {
milis = '0' + milis;
}
else if (milis <= 9) {
milis = '00' + milis;
}
t = h + ':' + m + ':' + s + '.' + milis;
return t;
}
function logi(msg){
dump('[INFO] <' + parseCurrentDate(new Date()) +'> [' + msg + ']\n');
}
function logw(msg){
dump('[WARN] <' + parseCurrentDate(new Date()) +'> [' + msg + ']\n');
}
function logd(msg){
dump('[DEBUG] <' + parseCurrentDate(new Date()) +'> [' + msg + ']\n');
}
function loge(msg){
dump('[ERROR] <' + parseCurrentDate(new Date()) +'> [' + msg + ']\n');
}
function initConsoleService()
{
if (consoleService == null) {
consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService( Components.interfaces.nsIConsoleService);
return true;
}
return false;
}
function dumpi(aMessage)
{
if(ENABLE_LOGGING == false) return ;
initConsoleService();
consoleService.logStringMessage('[INFO] <'+ parseCurrentDate(new Date()) +'> '+PROGRAM_LABEL_PREFIX+' [' + aMessage + ']');
logi(aMessage);
}
function dumpw(aMessage)
{
if(ENABLE_LOGGING == false) return ;
initConsoleService();
consoleService.logStringMessage('[WARN] <'+ parseCurrentDate(new Date()) +'> '+PROGRAM_LABEL_PREFIX+' [' + aMessage + ']');
logw(aMessage);
}
function dumpd(aMessage)
{
if(ENABLE_LOGGING == false) return ;
initConsoleService();
consoleService.logStringMessage('[DEBUG] <'+ parseCurrentDate(new Date()) +'> '+PROGRAM_LABEL_PREFIX+' [' + aMessage + ']');
logd(aMessage);
}
function dumpe(aMessage)
{
if(ENABLE_LOGGING == false) return ;
initConsoleService();
consoleService.logStringMessage('[ERROR] <'+ parseCurrentDate(new Date()) +'> '+PROGRAM_LABEL_PREFIX+' [' + aMessage + ']');
loge(aMessage);
}
function trim(str){
var str = String(str).replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
function openInNewTab(url, focus) {
var wm = Cc['@mozilla.org/appshell/window-mediator;1'].
getService(Ci.nsIWindowMediator);
var topWindow = wm.getMostRecentWindow('navigator:browser');
if (topWindow) {
var content = topWindow.document.getElementById('content');
content.selectedTab = content.addTab(url);
if (focus) {
topWindow.focus();
}
}
};
function goURL(url){
// first construct an nsIURI object using the ioservice
var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uriToOpen = ioservice.newURI(url, null, null);
var extps = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);
if (extps.externalProtocolHandlerExists("http")) {
// Handler for http:// URLs exists
// now, open it!
extps.loadURI(uriToOpen, null);
}
}
function escapeToLatin1(str){
if((str == null) || (str.length == 0) )
var str = String(str);
str = str.replace(/─ä/, '%a1');
str = str.replace(/─à/, '%b1');
str = str.replace(/─å/, '%c6');
str = str.replace(/─ç/, '%e6');
str = str.replace(/─ÿ/, '%ca');
str = str.replace(/─Ö/, '%ea');
str = str.replace(/Ł/, '%a3');
str = str.replace(/ł/, '%b3');
str = str.replace(/Ń/, '%d1');
str = str.replace(/ń/, '%f1');
str = str.replace(/Ó/, '%d3');
str = str.replace(/├│/, '%f3');
str = str.replace(/Ś/, '%a6');
str = str.replace(/ś/, '%b6');
str = str.replace(/┼╣/, '%ac');
str = str.replace(/┼║/, '%bc');
str = str.replace(/┼╗/, '%af');
str = str.replace(/┼╝/, '%bf');
return str;
};
///****************************
// public memebers and methods
///****************************
return {
// variables
//functions
dumpi:dumpi,
dumpw:dumpw,
dumpe:dumpe,
dumpd:dumpd,
trim:trim,
openInNewTab:openInNewTab,
goURL:goURL,
escapeToLatin1:escapeToLatin1
}
//-----------------------------
///****************************
// end of com.ksla.libs
///****************************
}();